<%@ page language="java" pageEncoding="UTF-8" %>
<%@ include file="/base.jsp" %>
<%@ include file="/module/taglibs.jsp" %>
<%@ include file="/module/nocache.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    <title>党支部管理</title>
    <%@ include file="/module/js.jsp" %>
</head>
<body>
<form action="#" name="Form" id="Form" method="post">
    <%--     <input type="hidden" name="projectId" id="projectId"  value="${projectId}"/> --%>
    <input type="hidden" name="idList" id="idList"/>
    <input type="hidden" id="bodyData" name="bodyData" value=""/>
    <table cellpadding="1" cellspacing="1" border="0">
        <c:if test="${_login_user_type==2}">
            <tr>
                <td><input type="button" id="btnQuery" value="查询"
                           class="inputButton"/>
                </td>
                <td>
                    <%--<kl:permission permisstionList="${permisstionList}"--%>
                                   <%--currentUser="${_login_console_user}"--%>
                                   <%--currentCatalogId="<%=CatalogUtils.getCatalogId(\"ZHDJ_GRDJ_DZB\")%>" key="add">--%>
                        <input type="button" id="btnAdd" value="添 加" class="inputButton"/>
                    <%--</kl:permission>--%>
                </td>
                <td>
                    <kl:permission permisstionList="${permisstionList}"
                                   currentUser="${_login_console_user}"
                                   currentCatalogId="<%=CatalogUtils.getCatalogId(\"ZHDJ_GRDJ_DZB\")%>" key="delete">
                        <input type="button" id="btnDelete" value="删除" class="inputButton"/>
                    </kl:permission>
                </td>
                <td><input type="button" id="btnExport" value="导出"
                           class="inputButton"/></td>
            </tr>
        </c:if>
    </table>
    <table cellpadding="1" cellspacing="1">
        <tr>
            <td>党支部名称：</td>
            <td><input type="text" name="dZBMC" id="dZBMC" autocomplete="off" class="inputText2"/></td>
        </tr>
    </table>
    <table id="dg">
        <%--<thead>--%>
        <%--<tr>--%>
            <%--<th data-options="field:'zBID',checkbox:true,width:60,align:'center'"></th>--%>
            <%--<th data-options="field:'dZBMC',sortable:true,nowrap:true,width:300,align:'center',formatter:formater">--%>
                <%--党支部名称--%>
            <%--</th>--%>
            <%--<th data-options="field:'dZBSJXM',sortable:true,nowrap:true,width:300,align:'center'">党支部书记</th>--%>
            <%--<th data-options="field:'cLRQ',sortable:true,nowrap:true,width:200,align:'center',formatter:formatDate">--%>
                <%--成立时间--%>
            <%--</th>--%>
            <%--<th data-options="field:'bJJMRQ',nowrap:false,width:300,align:'center',sortable:true,formatter:formatDate">--%>
                <%--本届届满日期--%>
            <%--</th>--%>
        <%--</tr>--%>
        <%--</thead>--%>
    </table>
</form>
<script>
    function formatDate(value) {
        var date = new Date(value);
        var y = date.getFullYear();
        var m = date.getMonth() + 1;
        var d = date.getDate();
        var h = date.getHours();       //获取当前小时数(0-23)
        var mm = date.getMinutes();     //获取当前分钟数(0-59)
        var s = date.getSeconds();     //获取当前秒数(0-59)
        return y + '-' + (m < 10 ? ('0' + m) : m) + '-' + (d < 10 ? ('0' + d) : d) + ' :' + (h < 10 ? ('0' + h) : h) + ':' + (mm < 10 ? ('0' + mm) : mm) + ':' + (s < 10 ? ('0' + s) : s);
    }


    function formater(value, row, index) {
        return "<a href='${basePath}/dzb/view?zBID=" + row.zBID + "'>" + row.dZBMC + "</a>";
    }
</script>


<script type="text/javascript">

    $(document).ready(function () {

        $('#dg').datagrid({
            url:'${basePath}/dzb/getListData',
            pagination:true,
            collapsible:true,
            method:'post',
            remoteSort:true,
            columns:[[
                {field:'zBID',checkbox:true,width:60,align:'center'},
                {field:'dZBMC',title:'党支部名称',width:300,align:'center',formatter:formater,sortable:true,nowrap:true},
                {field:'dZBSJXM',title:'党支部书记',width:300,align:'center',sortable:true,nowrap:true},
                {field:'cLRQ',title:'成立时间',width:200,align:'center',formatter:formatDate,sortable:true,nowrap:true},
                {field:'bJJMRQ',title:'本届届满日期',width:300,align: 'center',formatter:formatDate,sortable:true,nowrap:true}
            ]],
            rowStyler: function (index, row) {
            },
            onLoadSuccess: function (data) {//加载完毕后获取所有的checkbox遍历
                if (data.rows.length > 0) {
                }
            },
        });

        $('#btnAdd').click(function () {
            window.location.href = "${basePath}/dzb/add";
        });


        //查询
        $('#btnQuery').click(function () {
            $('#dg').datagrid('load', {
                dZBMC: $('#dZBMC').val()
            });
        });
        // 删除
        $('#btnDelete').click(function () {
            $("#idList").val("");
            var count = 0;
            var idList = new Array();
            var sels = $("#dg").datagrid("getSelections");
            for (var i in sels) {
                idList.push(sels[i].zBID);
                count++;
            }
            if (count == 0) {
                layer.alert("您至少选择一条删除记录信息", {icon: 3});
                return false;
            } else {
                layer.confirm("您是否删除当前选中数据信息", {icon: 3, title: '提示', skin: 'layer-ext-moon'}, function (index) {
                    $("#idList").val(idList);
                    var idlist = $("#idList").val();
                    $.ajax({
                        type: "POST",
                        url: "${basePath}/dzb/validation_delete",
                        data: {"idList": idlist},
                        dataType: "json",
                        success: function (result) {
                            if (result.length > 0) {
                                layer.alert("该支部内有党员，不可删除", {icon: 3});
                            } else {
                                document.Form.action = "${basePath}/dzb/delete";
                                document.Form.submit();
                            }
                        }
                    })
                }, function (index) {
                    layer.close(index);
                });
            }
        });
    });


    // 更新
    $('#btnUpdate').click(function () {
        var count = 0;
        var zBID = null;
        var sels = $("#dg").datagrid("getSelections");
        for (var i in sels) {
            if (count == 1) {
                layer.alert("只能允许选择一条编辑记录信息", {icon: 3});
                return false;
            }
            zBID = sels[i].zBID;
            count++;
        }
        if (count == 0) {
            layer.alert("请选择一条编辑记录信息", {icon: 3});
            return false;
        } else {
            window.location.href = "${basePath}/dzb/edit?id=" + zBID;
        }
    });

    if ("${msg}" != "") {
        layer.alert("${msg}", {icon: 6});
    }

    $('#btnExport').on('click', function () {
        layer.confirm("您确定要导出吗?", {icon: 3, title: '提示', skin: 'layer-ext-moon'}, function (index) {
            //var rows = $("#dg").datagrid("getRows");
            // var bodyData = JSON.stringify(rows);  //转成json字符串
            // $("#bodyData").val(JSON.stringify(rows));
            var dZBMC = $("#dZBMC").val();
            document.Form.action = "${basePath}/dzb/export_dzb?dZBMC=" + dZBMC;
            document.Form.submit();


            layer.close(index);
        });
    });

</script>
</body>
</html>
